#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
};
MainWindow::~MainWindow()
{
    delete ui;
}
void MainWindow::mousePressEvent(QMouseEvent *event){

    ui->pushButton->setText(tr("%1 ,%2").arg(event->x()).arg(event->y()));
}

void MainWindow::keyPressEvent(QKeyEvent *event){

  int x=ui->pushButton->x();
  int y=ui->pushButton->y();
  switch (event->key()) {
  case Qt::Key_W:
      ui->pushButton_2->setText(tr("W"));
      ui->pushButton->move(x,y-10);
      break;
  case Qt::Key_S:
      ui->pushButton_2->setText(tr("S"));
      ui->pushButton->move(x,y+10);
      break;
  case Qt::Key_A:
      ui->pushButton_2->setText(tr("A"));
      ui->pushButton->move(x-10,y);
      break;
  case Qt::Key_D:
      ui->pushButton_2->setText(tr("W"));
      ui->pushButton->move(x+10,y);
      break;
  default:
      break;
  }
}

